<?php

interface menu
{
	public function __construct(&$app);
	public function load();
	public function render();
}

class ulist_1lvl_menu implements menu
{
	var $app;
	var $filtered_menu;
	
	function __construct(&$app)
	{
		$this->app =& $app;
	}
	
	function load()
	{
		// filters the menu items for only ones we will use
		$access_level = $this->app->sess->access_level;
		$loggedin = $this->app->sess->isLoggedIn();
		
		global $config;
		$base_menu = $config['menu'];
		$this->filtered_menu = array();
		foreach($base_menu as $curnode)
		{
			if ($curnode['Type'] == 'Item')
			{
				if ($curnode['Auth']=="Any" || 
					($curnode['Auth']=='No' && !$loggedin) ||
					($curnode['Auth']=='Yes' && $loggedin) )
				{
					if ($curnode['AccessLevel'] <= $access_level)
					{
						$this->filtered_menu[] = array($curnode['Name'],$curnode['Content']);
					}
				}
			}
			else
			{
				// error - type "Menu" is disallowed by this class
				return false;
			}
			
		}		
		return true; // success
	}
	
	function render()
	{
		$html = "<ul class=\"menu\">";
		foreach($this->filtered_menu as $cur)
		{
			$html .= "<li><a href=\"" . $cur[1] . "\">" . $cur[0] . "</a></li>";
		}
		
		$html .= "</ul>";
		return $html;
	}
}

?>